package com.tgy.查找;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/***
 * @ClassName: SeqSearch
 * @Description: 线性查找
 * @Auther: tanggy3
 * @Date: 11:15 2022/8/31
 * @version : V1.0
 */
public class SeqSearch {
    public static void main(String[] args) {
        int[] arr1 = {5, 15, -5, 4, 6, 9, 5};
        int[] arr = {3, 3};
        System.out.println(seqSearchList(arr, 3).toString());
        seqSearchList(arr, 3);
    }

    static List<Integer> seqSearchList(int[] arr, int num) {
        ArrayList<Integer> ints = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                ints.add(i+1);
            }
        }
        return ints;
    }


    static int seqSearch(int[] arr, int num) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num) {
                return i;
            }
        }
        return -1;
    }
}
